home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / WINPROGS / UPC12BS1.ZIP / LIB / MKTEMPNM.C < prev    next >
C/C++ Source or Header  |  1993-06-06  |  3KB  |  92 lines

  1. /*--------------------------------------------------------------------*/
  2. /*    m k t e m p n m . c                                             */
  3. /*                                                                    */
  4. /*    Host Support routines for UUPC/extended                         */
  5. /*                                                                    */
  6. /*    Changes Copyright 1990, 1991 (c) Andrew H. Derbyshire           */
  7. /*                                                                    */
  8. /*    History:                                                        */
  9. /*       21Nov1991 Break out of hlib.c                         ahd    */
  10. /*--------------------------------------------------------------------*/
  11.  
  12. /*--------------------------------------------------------------------*/
  13. /*                          RCS Information                           */
  14. /*--------------------------------------------------------------------*/
  15.  
  16. /*
  17.  *    $Id: MKTEMPNM.C 1.4 1993/06/06 15:04:05 ahd Exp $
  18.  *
  19.  *    Revision history:
  20.  *    $Log: MKTEMPNM.C $
  21.  *     Revision 1.4  1993/06/06  15:04:05  ahd
  22.  *     Use process id for first temp file number
  23.  *
  24.  *     Revision 1.3  1993/04/11  00:31:04  ahd
  25.  *     Global edits for year, TEXT, etc.
  26.  *
  27.  * Revision 1.2  1992/11/19  02:57:07  ahd
  28.  * drop rcsid
  29.  *
  30.  * Revision 1.1  1992/11/16  05:00:26  ahd
  31.  * Initial revision
  32.  *
  33.  */
  34.  
  35. /*--------------------------------------------------------------------*/
  36. /*                        System include files                        */
  37. /*--------------------------------------------------------------------*/
  38.  
  39. #include <stdio.h>
  40. #include <stdlib.h>
  41. #include <string.h>
  42. #include <limits.h>
  43. #include <time.h>
  44.  
  45. #include <io.h>
  46. #include <process.h>
  47.  
  48.  
  49. /*--------------------------------------------------------------------*/
  50. /*                    UUPC/extended include files                     */
  51. /*--------------------------------------------------------------------*/
  52.  
  53. #include "lib.h"
  54. #include "hlib.h"
  55.  
  56. /*--------------------------------------------------------------------*/
  57. /*                          Global variables                          */
  58. /*--------------------------------------------------------------------*/
  59.  
  60. currentfile();
  61.  
  62. /*--------------------------------------------------------------------*/
  63. /*    m k t e m p n a m e                                             */
  64. /*                                                                    */
  65. /*    Generate a temporary name with a pre-defined extension          */
  66. /*--------------------------------------------------------------------*/
  67.  
  68. char *mktempname( char *buf, char *extension)
  69. {
  70.    static size_t file = 0;
  71.  
  72.    if ( file == 0 )
  73.       file = getpid() & 0x7FFF;  // Make unique number less than 32K
  74.  
  75.    if (buf == NULL)           /* Do we need to allocate buffer?         */
  76.    {
  77.       buf = malloc( FILENAME_MAX );
  78.       checkref(buf);
  79.    } /* if */
  80.  
  81.    for (file++ ; file < INT_MAX ; file++ )
  82.    {
  83.       sprintf(buf,"%s/uupc%04.4x.%s", E_tempdir, file, extension);
  84.       if ( access( buf, 0 ))  /* Does the host file exist?           */
  85.          break;               /* No  --> Use the name                */
  86.    } /* for */
  87.  
  88.    printmsg(5,"Generated temporary name: %s",buf);
  89.    return buf;
  90.  
  91. } /* mktempname */
  92.